package com.wl.jetpackdemo.anylayer

import android.os.Bundle
import android.view.Gravity
import android.view.MenuItem
import android.widget.Button
import android.widget.TextView
import com.wl.jetpackdemo.R
import com.wl.jetpackdemo.base.BaseActivity
import com.wl.jetpackdemo.base.BaseViewModel
import com.wl.jetpackdemo.databinding.ActivityAnyLayerBinding
import per.goweii.anylayer.AnyLayer
import per.goweii.anylayer.dialog.DialogLayer
import per.goweii.anylayer.popup.PopupLayer


class AnyLayerActivity : BaseActivity() {
    private lateinit var binding: ActivityAnyLayerBinding
    private lateinit var dialogLayer: DialogLayer
    private lateinit var popupLayer: PopupLayer

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityAnyLayerBinding.inflate(layoutInflater)
        setContentView(binding.root)
        supportActionBar?.setDisplayHomeAsUpEnabled(true)
        title = "AnyLayer"


        binding.btnDialog.setOnClickListener {
            dialogLayer = AnyLayer.dialog(this)
               .contentView(R.layout.dialog_anylayer_test)
               .backgroundColorRes(R.color.dialog_bg)
               .gravity(Gravity.CENTER)
               .cancelableOnTouchOutside(true)
               .cancelableOnClickKeyBack(true)

             dialogLayer.bindData {
                   var tvTitle = it.getView<TextView>(R.id.tv_title)
                   tvTitle?.text = "测试对话框"

                   it.getView<Button>(R.id.btn_cancel)?.setOnClickListener {
                       if(dialogLayer != null)
                           dialogLayer.dismiss()
                   }
               }
            dialogLayer.show()

       }

        binding.btnPopup.setOnClickListener {
            popupLayer = AnyLayer.popup(binding.btnPopup)

            popupLayer.contentView(R.layout.popup_layany_test)

            popupLayer
                .direction(PopupLayer.Align.Direction.VERTICAL)
                .horizontal(PopupLayer.Align.Horizontal.CENTER)
                .vertical(PopupLayer.Align.Vertical.BELOW)
                .inside(true)

//            popupLayer.createContentAnimator(object )

            popupLayer.show()
        }

        binding.btnToast.setOnClickListener {
            AnyLayer.toast()
                .backgroundColorInt(resources.getColor(R.color.black))
                .textColorInt(resources.getColor(R.color.white))
                .duration(3000)
//                .icon(if (isSucc) R.drawable.ic_success else R.drawable.ic_fail)
                .message("toast message")
                .show()
        }
    }

    override fun onOptionsItemSelected(item: MenuItem): Boolean {
        when(item.itemId) {
            android.R.id.home -> finish()
        }

        return super.onOptionsItemSelected(item)
    }


    override fun generateViewModel(): BaseViewModel? {
        return null
    }
}